﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Configuration;
using Data.Interfaces.Callback;
using Data.Interfaces;
namespace LeagueOfRila
{
    public static class Services
    {

        public static IConnectService serverConnectService;
        public static IFightService serverFightService;
        public static IGameService serverGameService;
        public static IPlayerService serverPlayerService;

        public static IConnectService GetConnectService(ICConnectService callback)
        {
            if (serverConnectService == null)
            {
                EndpointAddress address = new EndpointAddress(String.Format(ConfigurationSettings.AppSettings["ConnectServiceServerAdress"], ConfigurationSettings.AppSettings["adresseIp"]));
                DuplexChannelFactory<IConnectService> duplexChannel = new DuplexChannelFactory<IConnectService>(callback, new NetTcpBinding(SecurityMode.None), address);
                serverConnectService = duplexChannel.CreateChannel();
            }
            return serverConnectService;
        }

        public static IFightService GetFightService(ICFightService callback)
        {
            if (serverFightService == null)
            {
                EndpointAddress address = new EndpointAddress(String.Format(ConfigurationSettings.AppSettings["FightServiceServerAdress"], ConfigurationSettings.AppSettings["adresseIp"]));
                DuplexChannelFactory<IFightService> duplexChannel = new DuplexChannelFactory<IFightService>(callback, new NetTcpBinding(SecurityMode.None), address);
                serverFightService = duplexChannel.CreateChannel();
            }
            return serverFightService;
        }

        public static IGameService GetGameService(ICGameService callback)
        {
            if (serverGameService == null)
            {
                EndpointAddress address = new EndpointAddress(String.Format(ConfigurationSettings.AppSettings["GameServiceServerAdress"], ConfigurationSettings.AppSettings["adresseIp"]));
                DuplexChannelFactory<IGameService> duplexChannel = new DuplexChannelFactory<IGameService>(callback, new NetTcpBinding(SecurityMode.None), address);
                serverGameService = duplexChannel.CreateChannel();
            }
            return serverGameService;
        }

        public static IPlayerService GetPlayerService(ICPlayerService callback)
        {
            if (serverPlayerService == null)
            {
                EndpointAddress address = new EndpointAddress(String.Format(ConfigurationSettings.AppSettings["PlayerServiceServerAdress"], ConfigurationSettings.AppSettings["adresseIp"]));
                DuplexChannelFactory<IPlayerService> duplexChannel = new DuplexChannelFactory<IPlayerService>(callback, new NetTcpBinding(SecurityMode.None), address);
                serverPlayerService = duplexChannel.CreateChannel();
            }
            return serverPlayerService;
        }
    }
}
